package com.cqu.hhx.driver.service.impl;

import com.cqu.hhx.driver.entity.Customer;
import com.cqu.hhx.driver.entity.Driver;
import com.cqu.hhx.driver.entity.Manager;
import com.cqu.hhx.driver.mapper.CustomerMapper;
import com.cqu.hhx.driver.mapper.DriverMapper;
import com.cqu.hhx.driver.mapper.ManagerMapper;
import com.cqu.hhx.driver.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author DJ
 * @create 2020-05-23 19:05
 */
@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private ManagerMapper managerMapper;
    @Autowired
    private CustomerMapper customerMapper;
    @Autowired
    private DriverMapper driverMapper;

    /**
     * 验证管理员登录
     * @param account
     * @param password
     * @return  1：代表账户不存在 2：代表密码错误 0：代表登录成功
     */
    @Override
    public Integer checkManagerLogin(String account, String password) {
        Manager manager=managerMapper.getManagerInfo(account);
        if(manager==null){
            return 1;
        }else{
            if(password.equals(manager.getPassWord())){
                return 0;
            }else{
                return 2;
            }
        }
    }

    /**
     * 验证乘客登录
     * @param account
     * @param password
     * @return 成功返回乘客信息，失败返回null
     */
    @Override
    public Customer checkCustomerLogin(String account, String password) {
        try {
            Customer customer = customerMapper.getCustomerInfo(account);
            return customer;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 验证司机登录信息
     * @param account
     * @param password
     * @return 成功返回司机信息，失败返回null
     */
    @Override
    public Driver checkDriverLogin(String account, String password) {
        try{
            Driver driver=driverMapper.getDriverInfo(account);
            if(password.equals(driver.getPassWord())){
                return driver;
            }else{
                return null;
            }

        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
